package roborally.model.filters;
import roborally.model.*;
import roborally.model.interfaces.*;

public class EnergyAmountFilter extends ElementFilter{

	private final boolean min;
	private final EnergyAmount energyAmount;
	
	public EnergyAmountFilter(boolean min, EnergyAmount energyAmount){
		this.min = min;
		this.energyAmount = energyAmount;
	}
	
	@Override
	public boolean validate(Element element){
		if(element == null || element.getField() == null) return false;
		if(element instanceof EnergyHolder){
			if(min) return ((EnergyHolder) element).getEnergy().compareTo(this.energyAmount) != -1; //if the energy contained by element is not smaller than the minimum amount specified by this filter, true is returned.
			else return ((EnergyHolder) element).getEnergy().compareTo(this.energyAmount) != 1; //if the energy contained by element is not larger than the minimum amount specified by this filter, true is returned.
		}
		return false; //the element is not an EnergyHolder.
	}

}
